import os,sys,importlib,app_config
from ffmpy import FFmpeg

# 主菜单
app_config.mainmenu()

# 进入主程序

# 音频提取转换模块
number=str(input("请选择需要使用的功能（数字）"))
if number == "1":
    while True:
        file = str(input("请将需要处理的文件拖动到此："))
        file = app_config.file_path(file)
        if app_config.file_path_after(file) in app_config.video_suffix+app_config.audio_suffix:
            break
        else:
            print("不支持的文件格式，请重试")
            continue
    
    # 选择需要的音频格式
    print("1.mp3|2.flac|3.m4a")
    print("4.wma|5.ogg |6.aac")

    while True:
        multimedia = str(input("请输入需要提取/转换的格式:"))
        if multimedia == "1":
            extension = ".mp3"
            pass
        elif multimedia == "2":
            extension = ".flac"
            pass
        elif multimedia == "3":
            os.system('cls')
            ff = FFmpeg(inputs={file:None},
                outputs={file+app_config.file_suffix+app_config.audio_suffix[6]:'-vn -codec copy'}
            )
            print(ff.cmd)
            ff.run()
            os.system('cls')
            break
        elif multimedia == "4":
            extension = ".wma"
            pass
        elif multimedia == "5":
            extension = ".ogg"
            pass
        elif multimedia == "6":
            extension = ".aac"
            pass
        else:
            print("输入错误，请重新输入:")
            continue
        
        if multimedia == "3":
            pass
        else:
            os.system('cls')
            ff = FFmpeg(inputs={file: None},
                outputs={file + app_config.file_suffix + extension: '-vn'})
            print(ff.cmd)
            ff.run()
            os.system('cls')

# 视频转换模块
elif number == "2":
    file = str(input("请拖入需要转换的视频："))
    file = app_config.file_path(file)

    print("1.mp4|2.avi|3.wmv")
    print("4.rmvb|5.flv|6.f4v")

    while True:
        multimedia = str(input("请选择需要转换的视频格式："))
        if multimedia == "1":
            extension = ".mp4"
        elif multimedia =="2":
            extension = ".avi"
        elif multimedia =="3":
            extension = ".wmv"
        elif multimedia =="4":
            extension = ".rmvb"
        elif multimedia =="5":
            extension = ".flv"
        elif multimedia =="6":
            extension = ".f4v"
        else:
            print("输入错误，请重新输入")
            continue

        if multimedia == "1":
            os.system('cls')
            ff = FFmpeg(inputs={file: None},
                outputs={file + app_config.file_suffix + extension: '-vcodec copy -acodec copy'})
            print(ff.cmd)
            ff.run()
            os.system('cls')
        else:
            os.system('cls')
            ff = FFmpeg(inputs={file: None},
                outputs={file + app_config.file_suffix + extension: None})
            print(ff.cmd)
            ff.run()
            os.system('cls')

elif number == "3":  #视频快速剪辑
    file = str(input("请拖入需要处理的视频："))
    file = app_config.file_path(file)

    if app_config.file_path_after(file) in app_config.video_suffix:
        inedit = str(input("请输入剪辑的起始时间："))
        outedit = str(input("请输入剪辑的结束时间："))
        os.system('cls')
        ff = FFmpeg(inputs={file:'-ss '+inedit},
                outputs={file+"-out": '-vcodec copy -acodec copy -to'+" "+outedit})
        print((ff.cmd).replace('"', ''))
        ff.run()
        os.system('cls')
    else:
        print("error")
else:
    print("输入错误，请重新输入:")